package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.MyAutoWired;
import com.lagou.edu.mvcframework.annotations.MyController;
import com.lagou.edu.mvcframework.annotations.MyRequestMapping;
import com.lagou.edu.mvcframework.annotations.MySecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@MyController
@MyRequestMapping("/demo")
@MySecurity({"admin"})
public class DemoController {

    @MyAutoWired
    private IDemoService demoService;

    @MyRequestMapping("/query")
    @MySecurity({"tom","jack"})
    public String query(HttpServletRequest request, HttpServletResponse response, String username) throws IOException {
        response.setHeader("content-type", "text/html;charset=utf-8");
        response.getWriter().write(demoService.query(username));
        return demoService.query(username);
    }

    @MyRequestMapping("/query1")
    @MySecurity({"zhangsan"})
    public String query1(HttpServletRequest request, HttpServletResponse response, String username) throws IOException {
        response.setHeader("content-type", "text/html;charset=utf-8");
        response.getWriter().write(demoService.query(username));
        return demoService.query(username);
    }
}
